package com.xjnt.frameworks.web.message;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * @FileName : RetDataMsg.java
 * @Description :
 * @Copyright : Copyright (c) 2015
 * @author caoyong
 * @date Jul 29, 2015 3:12:49 PM
 */
public class RetDataMsg extends RetMsg {

	private static final long serialVersionUID = 1L;

	private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	private boolean needDateFmt = false;
	private String dateFormat = DATE_FORMAT;
	
	private int total = 0;
	private Object rows;

	/**
	 * @param needDateFmt
	 */
	public RetDataMsg(boolean needDateFmt) {
		this(needDateFmt, DATE_FORMAT);
	}
	
	/**
	 * @param dateFormat
	 */
	public RetDataMsg(String dateFormat) {
		this(true, dateFormat);
	}

	private RetDataMsg(boolean needDateFmt, String dateFormat) {
		this.needDateFmt = needDateFmt;
		this.dateFormat = dateFormat;
	}

	public int getTotal() {
		return total;
	}
	
	public void setTotal(int total) {
		this.total = total;
	}

	public Object getRows() {
		return rows;
	}
	
	public void setRows(Object data) {
		if(needDateFmt){
			String json = JSON.toJSONStringWithDateFormat(data, this.dateFormat, SerializerFeature.WriteDateUseDateFormat);
			this.rows = JSON.parse(json);
		}
		this.rows = JSON.parse(JSON.toJSONString(data));
	}
	
}
